import { createSlice, type PayloadAction } from '@reduxjs/toolkit'

export interface UserState {
  token: string | null
  nickname: string | null
}

const initialState: UserState = {
  token: null,
  nickname: null,
}

const userSlice = createSlice({
  name: 'user',
  initialState,
  reducers: {
    setToken(state, action: PayloadAction<string | null>) {
      state.token = action.payload
    },
    setNickname(state, action: PayloadAction<string | null>) {
      state.nickname = action.payload
    },
    resetUser() {
      return initialState
    },
  },
})

export const { setToken, setNickname, resetUser } = userSlice.actions
export default userSlice.reducer


